package com.bot.nft.module.dc.api;

import com.bot.auth.core.pojo.SaBaseClientLoginUser;
import com.bot.auth.core.util.StpClientLoginUserUtil;
import com.bot.common.pojo.CommonResult;
import com.bot.nft.module.dc.controller.DcSellOrderInfoController;
import com.bot.nft.module.dc.domain.vo.DcSellOrderInfoVo;
import com.bot.nft.module.dc.service.IDcSellOrderInfoService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author RenXiaoZheng
 * @since 2024-01-24
 */
@RestController
@RequestMapping("/app/conOrd")
@CrossOrigin
public class AppDcSellOrderInfoController extends DcSellOrderInfoController {

    @Resource
    public IDcSellOrderInfoService iDcOrderInfoService;

    //二级市场藏品下单
    @RequestMapping("/{sellId}/placeAnOrder.do")
    public CommonResult<String> placeOrder(@PathVariable String sellId) {

        SaBaseClientLoginUser clientLoginUser = StpClientLoginUserUtil.getClientLoginUser();
        String mbId = clientLoginUser.getId();
        String orderId = iDcOrderInfoService.placeOrder(sellId, mbId);
        return CommonResult.data(orderId);
    }

    //查看二级市场藏品订单单
    @RequestMapping("/{orderId}/viewOrder.do")
    public CommonResult<DcSellOrderInfoVo> viewOrder(@PathVariable String orderId) {

        DcSellOrderInfoVo dcSellOrderInfoVo = iDcOrderInfoService.viewOrder(orderId);
        return CommonResult.data(dcSellOrderInfoVo);
    }

    //支付二级市场藏品订单
    @RequestMapping("/{orderId}/paySellOrder.do")
    public CommonResult<String> paySellOrder(@PathVariable String orderId) {
        SaBaseClientLoginUser clientLoginUser = StpClientLoginUserUtil.getClientLoginUser();
        String mbId = clientLoginUser.getId();
        Boolean flag = iDcOrderInfoService.payOrder(orderId, mbId);
        return flag ? CommonResult.ok() : CommonResult.error();
    }

    //取消支付
    @RequestMapping("/{orderId}/cancelPayOrder.do")
    public CommonResult<String> cancelPayOrder(@PathVariable String orderId) {
        SaBaseClientLoginUser clientLoginUser = StpClientLoginUserUtil.getClientLoginUser();
        String mbId = clientLoginUser.getId();
        Boolean flag = iDcOrderInfoService.cancelPayOrder(orderId);
        return flag ? CommonResult.ok() : CommonResult.error();
    }


}
